/**
 * @param {number[]} nums
 * @return {number}
 */
 var countQuadruplets = function(nums) {
  const n = nums.length
  let ans = 0
  for(let i = 0; i<n-3; i++){
    for(let j = i+1; j<n-2; j++){
      for(let k = j+1; k<n-1; k++){
        for(let m = k+1; m<n; m++){
          if(nums[i]+nums[j]+nums[k] === nums[m]){
            ans++
          }
        }
      }
    }
  }
  return ans
};